using System;
using System.Collections.Generic;
using System.Text;

namespace ReportMaintenanceUtility
{
	public class DefaultValue : GenericBase<DefaultValue>
	{
		#region PRIVATE MEMBERS
		private ValuesType _seed = null;
		private string _value = string.Empty;
		private int _idx = -1;
		#endregion

		#region PUBLIC PROPERTIES
		public string Value
		{
			get { return this._value; }
			set
			{
				this.PrepStateChange("Value");
				this._value = value;
			}
		}
		#endregion

		#region CONSTRUCTOR(S)
		private DefaultValue(DefaultValue dv)
		{
			if (dv == null)
			{
				throw new ArgumentNullException();
			}
			else
			{
				this._seed = (ValuesType)dv.CreateSeedCopy();
				this._idx = dv._idx;
				this.Initialize();
			}
		}
		public DefaultValue(ValuesType vt, int idx)
		{
			if (vt == null)
			{
				throw new ArgumentNullException();
			}
			else
			{
				this._seed = vt;
				this._idx = idx;
				this.Initialize();
			}
		}
		protected override void Initialize()
		{
			this._value = this._seed.Value[this._idx];
		}
		#endregion

		public override List<ChangeLog> SaveState()
		{
			List<ChangeLog> log = new List<ChangeLog>();

			if (this._isDirty)
			{
				if (this._seed != null && this._seed.Value != null && this._seed.Value.Length >= this._idx)
				{
					log.Add(new ChangeLog(ChangeType.DefaultValueChange, this._seed.Value[this._idx], this._value));
					this._seed.Value[this._idx] = this._value;
				}
			}
			this.ClearState();

			return log;
		}

		public override void RestoreState()
		{
			if (this._copy != null)
			{
				this._value = this._copy.Value;
			}
			this.ClearState();
		}

		public override bool EqualTo(DefaultValue other)
		{
			//throw new Exception("The method or operation is not implemented.");
			if (other == null)
			{
				return false;
			}
			if (this._value != other._value || this._idx != other._idx)
			{
				return false;
			}
			return true;
		}

		public override DefaultValue CreateDeepCopy()
		{
			return new DefaultValue(this);
		}

		public override object CreateSeedCopy()
		{
			ValuesType vts = new ValuesType();
			List<string> values = new List<string>(this._seed.Value);
			vts.Value = values.ToArray();
			return vts;
		}
	}
}
